package controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;



@Controller
public class UserController{
	
	/*@RequestMapping("login")
	public ModelAndView login(@RequestParam(value="usname",required = false,defaultValue="zhangsan")String uname,
			@RequestParam("upwd")String pwd){
		System.out.println(uname+"="+pwd);
		ModelAndView mv = new ModelAndView();
		mv.setViewName("home");
		mv.addObject("login", "hello");//Model
		mv.addObject("id", 20);
		return mv;
	}*/
	
	/*@RequestMapping("login")
	public String login(@RequestParam(value="usname",required = false,defaultValue="zhangsan")String uname,
			@RequestParam("upwd")String pwd,Model model){
		System.out.println(uname+"="+pwd);
		model.addAttribute("login", "hello");
		model.addAttribute("id", 21);
		return "home";
	}*/
	
	@RequestMapping("login")
	public String login(@RequestParam(value="usname",required = false,defaultValue="zhangsan")String uname,
			@RequestParam("upwd")String pwd,HttpServletRequest request,HttpSession session){
		
		if("zhangsan".equals(uname) && "123".equals(pwd)){
			//跳转home
			return "home";
			
		}
		//重定向index.jsp
		
		return "redirect:/index.jsp";
		//return "forward:/list";
		
	}
	
	@RequestMapping("list")
	public String list(){
		return "";
	}
}
